<?php

namespace app\admin\controller;

use app\admin\model\OrderModel;
use think\Controller;

class Order extends Controller
{
    public function order_list()
    {
        return $this->fetch('order_list');
    }

    public function list1()
    {
        $OrderModel = new OrderModel();
        $page = input('param.page');
        $limit = input('param.limit');
        $datalist = $OrderModel->list($page, $limit);
        $count = $OrderModel->count();
        $data = [
            'code' => 0,
            'msg' => 'ok',
            'count' => $count,
            'data' => $datalist
        ];
        return $data;
    }

    public function order_add()
    {
        if (request()->isPost()) {
            $data = [
                'order_no' => input('param.order_no'),
                'user_id' => input('param.user_id'),
                'order_date' => time(),
            ];
            $OrderModel = new OrderModel();
            $OrderModel->add($data);
        }

        return $this->fetch();
    }

    public function order_edit()
    {
        $OrderModel = new OrderModel();
        if (request()->isPost()) {
            $id = input('param.user_id');
            $data = [
                'order_status' => input('param.order_status'),
                'ship_status' => input('param.ship_status'),
            ];
            $OrderModel->update($id, $data);
        }
        return $this->fetch();
    }

    public function order_delete()
    {
        if (request()->isGet()) {
            $id = input('param.id');
            $OrderModel = new OrderModel();
            $OrderModel = $OrderModel->delete($id);

        }
    }

    public function order_like()
    {
        $order_no = input('param.order_no');
        $OrderModel = new OrderModel();
        $datalist = $OrderModel->like($order_no);
        $data = [
            'code' => 0,
            'msg' => 'ok',
            'count' => 100,
            'data' => $datalist
        ];
        return $data;
    }
}